﻿namespace ApiLib.Models;

/// <summary>
/// 从json读取配置
/// </summary>
public class AppConfig
{
    /// <summary>
    /// 环境，更换日志输出级别：Production,Development,Debug<br/>
    /// Production：swagegr关闭，sql只记录异常日志<br/>
    /// Development：swagger开启，sql记录所有日志<br/>
    /// Debug：swagger开启，sql记录所有日志，控制台打印sql参数
    /// </summary>
    public string Env { get; set; } = "Development";

    /// <summary>
    /// 启动Host地址，配置后HttpPort和HttpsPort失效
    /// </summary>
    public string Host { get; set; }

    /// <summary>
    /// Http端口地址
    /// </summary>
    public int? HttpPort { get; set; }

    /// <summary>
    /// Https端口地址
    /// </summary>
    public int? HttpsPort { get; set; }

    /// <summary>
    /// Redis连接：127.0.0.1:6379,password=123,defaultDatabase=13,poolsize=50,ssl=false,writeBuffer=10240,prefix=key前辍
    /// </summary>
    public string Redis { get; set; } = "";

    /// <summary>
    /// GoogleAuthenticator秘钥
    /// </summary>
    public string GoogleAuthenticatorKey { get; set; } = "";

    /// <summary>
    /// mongo数据库，默认localhost:27017<br/>
    /// 连接：mongodb://172.20.30.89:27017
    /// </summary>
    public string MongoHost { get; set; } = "";

    /// <summary>
    /// Mongo数据库
    /// </summary>
    public string MongoDb { get; set; } = "logs";

    /// <summary>
    /// Mongo超时时间（秒）
    /// </summary>
    public double MongoTimeout { get; set; } = 5;

    /// <summary>
    /// webdav地址
    /// </summary>
    public string WebdavHost { get; set; } = "";

    /// <summary>
    /// webdav用户
    /// </summary>
    public string WebdavUser { get; set; } = "";

    /// <summary>
    /// webdav密码
    /// </summary>
    public string WebdavPwd { get; set; } = "";

    /// <summary>
    /// webdav根地址
    /// </summary>
    public string WebdavRoot { get; set; } = "";

    /// <summary>
    /// webdav访问地址（替换根地址）
    /// </summary>
    public string WebdavUrl { get; set; } = "";

    /// <summary>
    /// 默认HTTP日志，.net自带，输出到日志
    /// </summary>
    public bool DefaultHttpLog { get; set; } = false;

    /// <summary>
    /// HTTP日志，输出到数据库
    /// </summary>
    public bool HttpLog { get; set; } = false;
    /// <summary>
    /// HTTP日志，打印请求体
    /// </summary>
    public bool HttpLogBody { get; set; } = false;
    /// <summary>
    /// HTTP日志，打印结果
    /// </summary>
    public bool HttpLogResult { get; set; } = false;

    /// <summary>
    /// 用户登录过期时间
    /// </summary>
    public int UserLoginExpireSeconds { get; set; } = 24 * 60 * 60;

    /// <summary>
    /// 生产环境
    /// </summary>
    public bool IsProd => Env == "Production";
    
    /// <summary>
    /// 开发环境
    /// </summary>
    public bool IsDev => Env == "Development";

    /// <summary>
    /// 测试环境
    /// </summary>
    public bool IsDebug => Env == "Debug";
}